//
//  GenericsCommand.swift
//  ArchitectGenerics
//
//  Created by 姚胜龙 on 2017/6/8.
//  Copyright © 2017年 姚胜龙. All rights reserved.
//

import UIKit
//泛型命令模式
//T是指接受者
class GenericsCommand<T>: TetrisCommandProtocal {

    private var reciver:T?
    private var instruction:(T)->Void //闭包页不知道接受者的类型

    init(reciver:T, instruction:@escaping (T)->Void)
    {
        self.reciver = reciver
        self.instruction = instruction
    }

    func execute() {
        self.instruction(self.reciver!)
    }

    //提供一个动态创建的命令
    class func createCommand(reciver:T, instruction:@escaping (T)->Void) -> TetrisCommandProtocal {
        return GenericsCommand(reciver: reciver, instruction: instruction)
    }

}
